<?php

##################################################
#
# Copyright (c) 2004-2006 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################

class filemanagermodule {
	function name() { return exponent_lang_loadKey('modules/filemanagermodule/class.php','module_name'); }
	function author() { return exponent_lang_loadKey('modules/filemanagermodule/class.php','module_author'); }
	function description() { return exponent_lang_loadKey('modules/filemanagermodule/class.php','module_description'); }
	function hasSources() { return false; }
	function hasContent() { return true; }
	function hasViews() { return true; }

	function supportsWorkflow() { return false; }

	function permissions($internal = "") {
		//$i18n = exponent_lang_loadFile('modules/filemanagermodule/class.php');
		
		/*if ($internal == "") {
			return array(
				'administrate'=>$i18n['perm_administrate'],
				'configure'=>$i18n['perm_configure'],
			);
		} else {
			return array(
				'administrate'=>$i18n['perm_administrate'],
				'configure'=>$i18n['perm_configure'],
			);
		}*/
		return array(
			'administrate'=>'Administrate',
			'configure'=>'Configure',
			'uploadfile'=>'Create',
			'approve'=>'Edit',
			'delete'=>'Delete',
			'add_collection'=>'Add Collection',
			'approve'=>'Approve Uploaded File'
			);
	}

	/**
	* This function return permission 
	* of the filemanagermodule
	* 
	* @author trungdt
	* @since Jul 4, 2011
	* 
	*/
	static function _GetLoc()
	{
		$loc=null;
		$loc->mod='filemanagermodule';
		$loc->int="";
		$loc->src="_syscore"; // force to use this src
		// TODO: must implement better
		return $loc;
	}
	
	/**
	* This function return true if current user can upload file 
	* 
	* @author trungdt
	* @since Jul 4, 2011
	*/
	static function _CanUpload(){
		$loc=filemanagermodule::_GetLoc();
		$pers=array("administrate","approve","delete","add_collection");
		$temp=exponent_permissions_check($pers,$loc);
		// hack this: because , we allow logged user to upload file, we should return true if they logged in
		return $temp || exponent_users_isLoggedIn() || exponent_users_isAdmin();
	}
	
	/**
	* This function return true if current user can approve file
	* 
	* @author trungdt
	* @since Jul 4, 2011
	*/
	static function _CanApprove(){
		$loc=filemanagermodule::_GetLoc();
		$pers=array("administrate","approve");
		$temp=exponent_permissions_check($pers,$loc);
		return $temp || exponent_users_isAdmin();
	}
	
	/**
	* This function return true if current user logged in as a normal user only
	* 
	* @author trungdt
	* @since Jul 4, 2011
	*/
	static function _CheckNormalUser(){
		$loc=filemanagermodule::_GetLoc();
		$pers=array("administrate","approve","delete","add_collection");
		$temp=exponent_permissions_check($pers,$loc);
		return (!$temp && exponent_users_isLoggedIn());
	}
	
	function show($view,$loc = null, $title = "") {
		$loc = exponent_core_makeLocation('filemanagermodule');

		global $db;
		$collections = $db->selectObjects('file_collection');

		$template = new template('filemanagermodule',$view,$loc);
		$template->assign('collections',$collections);

		$template->output();
	}

	function deleteIn($loc) {

	}

	function copyContent($oloc,$nloc) {

	}
}

?>
